#include <Eigen/Dense>
#include <iostream>
using namespace Eigen;
using std::cout, std::endl;

// Matrix的行数和列数是个变量，当代码运行到这的时候，
// 函数和列数就确定了，但代码不运行时，不知道行数和列数
// （无法编译时确定）需要使用动态矩阵
// method1: 构建长数组
// method2: new动态分配存储空间
// method3: vector 声明动态数组

// 动态数组的创建
void test_create_dynamic_matrix(){
    // Matrix
    Matrix<double, Dynamic, Dynamic> F1;
    MatrixXd F1_2;

    Matrix<int, 4, Dynamic> F2;
    Matrix4Xi F2_2;

    Matrix<float, Dynamic, 3> F3;
    MatrixX3f F3_2; 

    Matrix<double, Dynamic, 1> F4;
    VectorXd F4_2;

    Matrix<double, 1, Dynamic> F5;
    RowVectorXd F5_2;

    // Array
    Array<double, Dynamic, Dynamic> f6;
    ArrayXXd f6_2;

    Array<int, 4, Dynamic> f7;
    Array4Xi f7_2;

    Array<float, Dynamic, 3> f8;
    ArrayX3i f8_2;

    Array<double, Dynamic, 1> f9;
    ArrayXd f9_2;

}

void test_normal_init(){
    MatrixXd  A1(3, 4);
    A1 << 1,2,3,4,5,6,7,8,9,10,11,12;
    cout << "A1 = \n" << A1 << endl;

    MatrixXd A2;
    A2.resize(3,4);
    A2 << 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120;
    cout << "A2 = \n" << A2 << endl;
}

void test_special_init(){
    MatrixXd A4;
    A4=MatrixXd::Random(3,4);
    cout << "A4 = \n" << A4 << endl;

    // 报错：=是初始化运算，<<可以认为是赋值运算
    // 在赋值之前需要指导Matrix的大小
    // MatrixXd A5;
    // A5 << MatrixXd::Random(3,4);
    // cout << "A5 = \n" << A5 << endl;

    MatrixXd A6;
    A6.resize(3,4);
    A6 << MatrixXd::Random(3,4);
    cout << "A6 = \n" << A6 << endl;
}

void test_use_dynamic_matrix(){
    double flow_time = 10;
    double time_step = 0.001;
    int steps = flow_time / time_step;
    MatrixXd m(steps+1,4);

}


int main() { 

    test_create_dynamic_matrix();
    test_normal_init();
    test_special_init();
    test_use_dynamic_matrix();
    return 0; 
}